package com.abner.springcloud.consumer.movie.service;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.feign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: Abner.Jiang
 * @Description:
 * @Date: Created on 2019/12/26 17:20
 * @ProjectName: springcloud-provider-user
 */
@FeignClient(name = "springcloud-file-upload",configuration = UploadFeignClient.MultipartSupportConfig.class)
public interface UploadFeignClient {

    @RequestMapping(value = "/upload",method = RequestMethod.POST,
    produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},
    consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String handleFileUpload(@RequestPart("file")MultipartFile file);

    class MultipartSupportConfig{
        @Bean
        @Primary
        public Encoder multipartFormEncoder(){
            return new SpringFormEncoder();
        }
    }
}
